package com.miaostars.level;

import org.bukkit.plugin.java.JavaPlugin;
import com.miaostars.level.manager.PlayerDataManager;

public class LevelPlugin extends JavaPlugin {
    private PlayerDataManager dataManager;

    @Override
    public void onEnable() {
        saveDefaultConfig(); // 加载config.yml
        dataManager = new PlayerDataManager(this);
        getServer().getPluginManager().registerEvents(new CombatListener(dataManager), this);
        getServer().getPluginManager().registerEvents(new JoinListener(dataManager), this);
        getCommand("level").setExecutor(new LevelCommand(dataManager));
    }

    public void onEnable() {
        int maxCPS = getConfig().getInt("anti-cheat.max-cps", 20);
        int minInterval = getConfig().getInt("anti-cheat.min-interval-ms", 50);
       CPSValidator.loadConfig(maxCPS, minInterval);

       // 初始化数据同步
       JedisPool jedisPool = new JedisPool("redis-server.example.com", 6379);
       DataSource mysqlDS = setupMySQLDataSource(); // 需实现MySQL连接池
       DataSync dataSync = new DataSync(jedisPool, mysqlDS);
       dataSync.startBatchSave();
       dataSync.subscribeUpdates();
    }

   public void onEnable() {
       getServer().getPluginManager().registerEvents(
       new JoinListener(dataManager), this);
    }

    @Override
    public void onDisable() {
        dataManager.saveAllData(); // 关闭前保存数据
    }
}